package panels.util;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class JGroupBox extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String	captionChanged	= "captionChanged";

	private JPanel panel = new JPanel();
	private JLabel label = new JLabel("");
	protected	String			oldCaption = "";
	protected	JLabel			captionLbl = null;
	protected	JPanel		NCPanel = null;
	
	protected	JLinePanel	wPanel = null;
	protected	JLinePanel	nPanel = null;
	protected	JLinePanel	ePanel = null;
	protected	JLinePanel	sPanel = null;

	public JGroupBox() {
		panel = new JPanel();
		label = new JLabel("Group Box");
		
		wPanel = new JLinePanel();
		ePanel = new JLinePanel();
		sPanel = new JLinePanel();
		nPanel = new JLinePanel();
		
		nPanel.init(false,true,false,true);
		ePanel.init(true, false, true,false);
		sPanel.init(false, true, false, true);
		wPanel.init(true, false, true,false);
		
		NCPanel.setLayout(new GridLayout(1,2));
		NCPanel.add(label,BorderLayout.NORTH);
		NCPanel.add(nPanel);
		
		super.setLayout(new BorderLayout());
		super.add(panel,BorderLayout.CENTER);
		super.add(NCPanel,BorderLayout.NORTH);
		super.add(wPanel,BorderLayout.WEST);
		super.add(sPanel, BorderLayout.SOUTH);
		super.add(ePanel, BorderLayout.EAST);
	}
	
	public boolean checkCaptionFormat(String S) {
		return true;
	}
	
	public void add(JComponent C) {
		panel.add(C);
	}
	
	public synchronized void setCaption(String newCaption) {
		if (checkCaptionFormat(newCaption)) {
			oldCaption = getCaption();
			captionLbl.setText(newCaption);
			this.firePropertyChange(captionChanged,oldCaption,newCaption);
		}
	}
	
	public synchronized String	getCaption() {
		return captionLbl.getText();
	}

}
